
// Creating a teachers panel using baseline and endline teacher surveys

set more off


cd "/Users/stefanleeffers/Dropbox/Documents/2. ANGOLA/Angola Endline/Data/Teacher Panel/"

use "data_teachers_endline.dta", clear

keep TD_ss_key teacher_id2 TD_school_id TD_resp_id TD_resp_name TD_resp_tel

drop if TD_resp_tel==.

save "data_teachers_endline2.dta", replace




use "data_teachers_baseline.dta", clear

replace T_resp_tel = . if T_resp_name=="ana daconceiçao jesus"
drop if T_resp_tel == 928808566 & school_id==69

rename T_resp_tel TD_resp_tel

merge m:1 TD_resp_tel using "data_teachers_endline2.dta"

drop resp_name2

drop if school_id==.

// corrections

replace teacher_id2 = 224 if T_resp_name=="florisbela jaõa paulino"
replace teacher_id2 = 318 if T_resp_name=="julia paiva correia"
replace teacher_id2 = 411 if T_resp_name=="vitória saroa"
replace teacher_id2 = 401 if T_resp_name=="José Paulino"
replace teacher_id2 = 615 if T_resp_name=="LURDES ANTONIO"
replace teacher_id2 = 912 if T_resp_name=="EDWIGES JOAO"
replace teacher_id2 = 915 if T_resp_name=="Elisa Zeferino Antonio"
replace teacher_id2 = 1115 if T_resp_name=="ANTONIO FRANCISCO CARVALHO"
replace teacher_id2 = 1104 if T_resp_name=="SOFIA TENENTE"
replace teacher_id2 = 1317 if T_resp_name=="clotildi kuenda"
replace teacher_id2 = 1520 if T_resp_name=="maria agostinha abrantes fracisco"
replace teacher_id2 = 1504 if T_resp_name=="DOMINGOS LUANA"
replace teacher_id2 = 1511 if T_resp_name=="teofilo paciencia de americo"
replace teacher_id2 = 1517 if T_resp_name=="maria seleste teicheira"
replace teacher_id2 = 1606 if T_resp_name=="jose santiago"
replace teacher_id2 = 1609 if T_resp_name=="kembi  raquel domingos basolua"
replace teacher_id2 = 1814 if T_resp_name=="ana cardoso rato gusmao"
replace teacher_id2 = 2138 if T_resp_name=="mariquinha antonio jose"
replace teacher_id2 = 2101 if T_resp_name=="ester albino"
replace teacher_id2 = 2216 if T_resp_name=="VICTORIA SILVA ANTONIO DOS REIS"
replace teacher_id2 = 2406 if T_resp_name=="Francisca Antonio"
replace teacher_id2 = 2405 if T_resp_name=="Ilda Campos"
replace teacher_id2 = 2610 if T_resp_name=="elisabete gando"
replace teacher_id2 = 2703 if T_resp_name=="matateu sardinha quipeca"
replace teacher_id2 = 2803 if T_resp_name=="armando dinis"
replace teacher_id2 = 2902 if T_resp_name=="juaquina manuel da costa"
replace teacher_id2 = 3104 if T_resp_name=="CLAUDIA JOAO"
replace teacher_id2 = 3310 if T_resp_name=="alicerses januario funete"
replace teacher_id2 = 3408 if T_resp_name=="ENOQUE BAPTISTA GERMANO MANUEL"
replace teacher_id2 = 3402 if T_resp_name=="aldina rosa josias abias"
replace teacher_id2 = 3411 if T_resp_name=="MANUEL RAMOS"
replace teacher_id2 = 3410 if T_resp_name=="rosaria janga"
replace teacher_id2 = 3513 if T_resp_name=="delfina boy"
replace teacher_id2 = 3516 if T_resp_name=="LEDA MARIA CAMPO DIOGO"
replace teacher_id2 = 3509 if T_resp_name=="conceição antonio lopes"
replace teacher_id2 = 3603 if T_resp_name=="ANTÓNIO LUÍS"
replace teacher_id2 = 3609 if T_resp_name=="LOPES DOMINGOS RAUL"
replace teacher_id2 = 3704 if T_resp_name=="carlota domingos dacosta"
replace teacher_id2 = 3807 if T_resp_name=="Julia Chipanda"
replace teacher_id2 = 3822 if T_resp_name=="Eduardina Jose Fernandes"
replace teacher_id2 = 3907 if T_resp_name=="DAVID ARMANDO ANTONIO"
replace teacher_id2 = 3903 if T_resp_name=="ROSA ANTONIO FRANCISCO"
replace teacher_id2 = 4010 if T_resp_name=="ANA MARIA DA COSTA"
replace teacher_id2 = 4020 if T_resp_name=="ISMERALDA LUCAMBA"
replace teacher_id2 = 4103 if T_resp_name=="ANTONIO SELESTINO"
replace teacher_id2 = 4110 if T_resp_name=="DOMINGOS MATEUS"
replace teacher_id2 = 4105 if T_resp_name=="MANUEL MATIAS DA COSTA ABRANTES"
replace teacher_id2 = 4202 if T_resp_name=="lMACULADA CARLOS"
replace teacher_id2 = 4207 if T_resp_name=="RAQUEL MANUEL PONDA"
replace teacher_id2 = 4204 if T_resp_name=="INDILHANO JOAO MANUEL ANTONIO"
replace teacher_id2 = 4503 if T_resp_name=="ANA MARIA CELESTINO"
replace teacher_id2 = 4610 if T_resp_name=="fatima capingana"
replace teacher_id2 = 4707 if T_resp_name=="vitoria bandeira"
replace teacher_id2 = 5010 if T_resp_name=="nataliaventura"
replace teacher_id2 = 5306 if T_resp_name=="teresa jaime"
replace teacher_id2 = 5513 if T_resp_name=="JULIETA DA SILVA"
replace teacher_id2 = 6301 if T_resp_name=="DOMINGOS PRAZERIS ANTONIO"
replace teacher_id2 = 6502 if T_resp_name=="abertina cassua"
replace teacher_id2 = 6618 if T_resp_name=="gini  chimbinda"
replace teacher_id2 = 6603 if T_resp_name=="antonia zambo"
replace teacher_id2 = 6612 if T_resp_name=="elsa mario"
replace teacher_id2 = 6601 if T_resp_name=="amelia adelino"
replace teacher_id2 = 6804 if T_resp_name=="joao afredo antonio pronco"
replace teacher_id2 = 6802 if T_resp_name=="rosalina alfredo cahima"
replace teacher_id2 = 6809 if T_resp_name=="Joana Cafranca Januario"
replace teacher_id2 = 7004 if T_resp_name=="narcisio manuel"
replace teacher_id2 = 7188 if T_resp_name=="LEMBA AFONSO"
replace teacher_id2 = 7316 if T_resp_name=="irene domingos"
replace teacher_id2 = 7404 if T_resp_name=="ESMI PEDRO EDUARDO DOMINGOS"
replace teacher_id2 = 7504 if T_resp_name=="lentina afonso jacinto mateus"
replace teacher_id2 = 7622 if T_resp_name=="adelina calueio"
replace teacher_id2 = 7804 if T_resp_name=="joana kitembo"
replace teacher_id2 = 7908 if T_resp_name=="antonio jose francisco"
replace teacher_id2 = 8008 if T_resp_name=="REMUALDA FERREIRA MENDES"
replace teacher_id2 = 8210 if T_resp_name=="Gomes Raul"
replace teacher_id2 = 8313 if T_resp_name=="MARTACFRANCISCO AMERIC8 DA SILVA"
replace teacher_id2 = 8306 if T_resp_name=="LUIS AFONSO BORGES D JESUS REIS"
replace teacher_id2 = 8408 if T_resp_name=="JERMANO RAUL"
replace teacher_id2 = 8403 if T_resp_name=="FERREIRA CAETANO PINTO DA SILVA"
replace teacher_id2 = 8603 if T_resp_name=="RAUL JOAO"
replace teacher_id2 = 8803 if T_resp_name=="Maria Amelia Martins Neves"
replace teacher_id2 = 8906 if T_resp_name=="Domingas Francisco Fernando"
replace teacher_id2 = 8904 if T_resp_name=="António Candiero"
replace teacher_id2 = 9108 if T_resp_name=="Joaquim M.G.Neto"
replace teacher_id2 = 9208 if T_resp_name=="Enriqueta Roque"
replace teacher_id2 = 9217 if T_resp_name=="Julia dos Santos"
replace teacher_id2 = 9306 if T_resp_name=="Juliana Lino"
replace teacher_id2 = 9312 if T_resp_name=="Madalena Augosto"
replace teacher_id2 = 9511 if T_resp_name=="florinda gonsalo"
replace teacher_id2 = 9606 if T_resp_name=="Telescova Ilda da S. Jorge"
replace teacher_id2 = 9705 if T_resp_name=="Raul Manuel Tavares"
replace teacher_id2 = 9710 if T_resp_name=="Laurinda Fernando Ernesto"
replace teacher_id2 = 9915 if T_resp_name=="Celita Caniveti"
replace teacher_id2 = 10202 if T_resp_name=="Josefina Teresa"
replace teacher_id2 = 10311 if T_resp_name=="Cezar Mauicio"
replace teacher_id2 = 10308 if T_resp_name=="Alga Bartolomeo"
replace teacher_id2 = 10301 if T_resp_name=="Joao Ngola"
replace teacher_id2 = 10402 if T_resp_name=="Auberto Chama"
replace teacher_id2 = 10502 if T_resp_name=="ANTONICA BERNADO"
replace teacher_id2 = 10607 if T_resp_name=="DIONISIO ADELINO"
replace teacher_id2 = 10609 if T_resp_name=="PAULO CHIPUCO"
replace teacher_id2 = 10610 if T_resp_name=="MATILDE CANDIEGUE"
replace teacher_id2 = 10712 if T_resp_name=="MANUELA TEXEIRA"
replace teacher_id2 = 10804 if T_resp_name=="DOMINGOS AUGUSTO GONSALVES"
replace teacher_id2 = 10910 if T_resp_name=="EMENEGILDO ENRIQUES CARLOS FELGUEIRA"
replace teacher_id2 = 11101 if T_resp_name=="ISABEL ALBERTO DOMINGOS"
replace teacher_id2 = 11105 if T_resp_name=="COROLINA LUIS JOSE"
replace teacher_id2 = 11110 if T_resp_name=="AUGUSTO DA FONSECA PATRICIO"
replace teacher_id2 = 11218 if T_resp_name=="Araujo Raimundo"
replace teacher_id2 = 11304 if T_resp_name=="Dumingos Mutali"
replace teacher_id2 = 11388 if T_resp_name=="Jose dos Santos"
replace teacher_id2 = 11419 if T_resp_name=="BALTAZAR OLIVEIRA"
replace teacher_id2 = 11405 if T_resp_name=="Fernando Manuel"
replace teacher_id2 = 11407 if T_resp_name=="Pedro Caitano"
replace teacher_id2 = 11609 if T_resp_name=="Emilia Santareno"
replace teacher_id2 = 11608 if T_resp_name=="João Joaquim Luciano"
replace teacher_id2 = 11601 if T_resp_name=="Cecilia Luis"
replace teacher_id2 = 11808 if T_resp_name=="ALFREDO ANTONIO"
replace teacher_id2 = 11807 if T_resp_name=="QUARTIM LINO"
replace teacher_id2 = 11928 if T_resp_name=="ALBINO BUANDO"
replace teacher_id2 = 11919 if T_resp_name=="ALCINO ARMANDO"
replace teacher_id2 = 12012 if T_resp_name=="TERESA ADRIANO"
replace teacher_id2 = 12007 if T_resp_name=="MARILHA LUIS"
replace teacher_id2 = 12303 if T_resp_name=="MATIAS PEDRO"
replace teacher_id2 = 12306 if T_resp_name=="PEDRO CHAVONGA"
replace teacher_id2 = 12309 if T_resp_name=="CÉSAR LUPAMBO"
replace teacher_id2 = 12307 if T_resp_name=="FLAVIO LUCIANO DA SILVEIRA"
replace teacher_id2 = 12402 if T_resp_name=="PAULO CHIQUETE"
replace teacher_id2 = 12404 if T_resp_name=="CLAUDEHT SELESTINO"
replace teacher_id2 = 12509 if T_resp_name=="TEIXEIRA FERNANDO"
replace teacher_id2 = 12504 if T_resp_name=="MANUEL CHIMJEMBO"
replace teacher_id2 = 12616 if T_resp_name=="JOAO ANTNÍO"

gen changed = 0
replace changed = 1 if school_id!=TD_school_id

lab var changed "Changed school between baseline and endline"

drop _merge TD_ss_key TD_school_id TD_resp_id TD_resp_tel TD_resp_name

gen survey_type = 2

order school_id teacher_id2 changed survey_type

lab var teacher_id2 "Identification for merging"

// Renaming variabels to append with directors

rename T_* *

drop resp_id school_name vil_id commune_name bairro_name

drop 	TP11_C13 TP19_C4 TP21_C6 TP2_1_C6 TP2_38 TP2_3_C8 TP2_8_C8 TP2_11_C7 ///
		TP2_12_C6 TP2_1610 TP2_1611 TP2_16_C10 TP2_17_C7 TP2_186 TP2_187 	///
		TP2_18_C6 TP2_195 TP2_196 TP2_19_C5 TP2_211 TP2_212 TP2_213 TP2_214 ///
		TP2_215 TP2_216 TP2_21_C4 TP2_239 TP2_23_C9 TP3_7_C6 TP3_9_C6 		///
		TP3_131_C5 TP3_134_C5 TP3_18_C5 TP4_8_C6 TP4_10_C5 TP5_2_3_C11 		///
		TP5_8_9_C10 TP5_11_12_C10 TP9_1A_C80 TP9_1B_C81 TP9_1C_C82 TP6_27 	///
		TP7_101_C13 TP7_102_C14 TP7_103_C15 TP8_6_C4 TP8_10_C9 				///
		TP11_3_0_P11_4_C13 TP11_3_1_P11_4_C13 TP11_3_2_P11_4_C13 			///
		TP11_3_2_P11_7_C2 TP11_3_2_P11_7_C6 TP11_3_0_P11_11_C9 				///
		TP11_3_1_P11_11_C9 TP11_3_2_P11_11_C9 TP12_8_C10 TP12_11_C13

rename TQ1_01 TDbase_age
rename TQ1_02 TDbase_female
rename TQ1_03 TDbase_home_loc2
rename TQ1_03_01 TDbase_home_loc2_other1
rename TQ1_03_02 TDbase_home_loc2_other2
rename TQ1_03_03 TDbase_home_loc2_other3
rename TQ1_04 TDbase_origin_muni
rename TQ1_05 TDbase_origin2
rename TQ1_05_01 TDbase_origin2_other1
rename TQ1_05_02 TDbase_origin2_other2
rename TQ1_05_03 TDbase_origin2_other3
rename TQ1_06 TDbase_leaving_origin
rename TQ1_07 TDbase_arriving_home
rename TQ1_08 TDbase_edu
rename TQ1_09 TDbase_marital
rename TQ1_10 TDbase_edu_partner
rename TQ1_11 TDbase_ocu_partner
rename TQ1_12 TDbase_income
rename TQ1_13 TDbase_children
rename TQ1_14 TDbase_children_others
rename TQ1_15 TDbase_children_girls
rename TQ1_16 TDbase_children_school
rename TQ1_17_01 TDbase_child1_grade
rename TQ1_17_02 TDbase_child2_grade
rename TQ1_17_03 TDbase_child3_grade
rename TQ1_17_04 TDbase_child4_grade
rename TQ1_17_05 TDbase_child5_grade
rename TQ1_17_06 TDbase_child6_grade
rename TQ1_17_07 TDbase_child7_grade
rename TQ1_17_08 TDbase_child8_grade
rename TQ1_18 TDbase_language
rename TQ1_19 TDbase_home_type
rename TQ1_20 TDbase_transport_distance
rename TQ1_21 TDbase_transport_type
rename TQ1_22 TDbase_transport_time
rename TQ2_01 Tbase_school_ocu
rename TQ2_02 Tbase_qualification
rename TQ2_03_01 TDbase_training_1
rename TQ2_03_02 TDbase_training_2
rename TQ2_03_03 TDbase_training_3
rename TQ2_03_04 TDbase_training_4
rename TQ2_03_05 TDbase_training_5
rename TQ2_03_06 TDbase_training_6
rename TQ2_03_07 TDbase_training_7
rename TQ2_04 Tbase_teach_other_school_years
rename TQ2_05 Tbase_name_other_school
rename TQ2_06 Tbase_loc1_other_school
rename TQ2_07 Tbase_loc2_other_school
rename TQ2_08 Tbase_transfer_reason
rename TQ2_09 Tbase_teach_this_school_years
rename TQ2_10 Tbase_help_nomination
rename TQ2_11 Tbase_help_nomination_type
rename TQ2_12 TDbase_stay
rename TQ2_13 TDbase_salary
rename TQ2_14 TDbase_bonus_possible
rename TQ2_15 TDbase_bonus_received
rename TQ2_16_01 TDbase_evaluation_how_1
rename TQ2_16_02 TDbase_evaluation_how_2
rename TQ2_16_03 TDbase_evaluation_how_3
rename TQ2_16_04 TDbase_evaluation_how_4
rename TQ2_16_05 TDbase_evaluation_how_5
rename TQ2_16_06 TDbase_evaluation_how_6
rename TQ2_16_07 TDbase_evaluation_how_7
rename TQ2_16_08 TDbase_evaluation_how_8
rename TQ2_16_09 TDbase_evaluation_how_9
rename TQ2_17 TDbase_evaluation_who
rename TQ2_18_01 Tbase_consequence_good_1
rename TQ2_18_02 Tbase_consequence_good_2
rename TQ2_18_03 Tbase_consequence_good_3
rename TQ2_18_04 Tbase_consequence_good_4
rename TQ2_18_05 Tbase_consequence_good_5
rename TQ2_18_06 Tbase_consequence_good_6
rename TQ2_19_01 Tbase_consequence_bad_1
rename TQ2_19_02 Tbase_consequence_bad_2
rename TQ2_19_03 Tbase_consequence_bad_3
rename TQ2_19_04 Tbase_consequence_bad_4
rename TQ2_19_05 Tbase_consequence_bad_5
rename TQ2_20 Tbase_dir_can_dismiss
rename TQ2_21 TDbase_receive_help
rename TQ2_22 TDbase_other_income
rename TQ2_23_01 Tbase_other_income_type1
rename TQ2_23_02 Tbase_other_income_type2
rename TQ2_23_03 Tbase_other_income_type3
rename TQ2_23_04 Tbase_other_income_type4
rename TQ2_23_05 Tbase_other_income_type5
rename TQ2_23_06 Tbase_other_income_type6
rename TQ2_23_07 Tbase_other_income_type7
rename TQ2_23_08 Tbase_other_income_type8
rename TQ2_24 TDbase_other_income_value

rename TQ3_* TD3base_*
rename TQ4_* TDbase_04_*
rename TQ5_* TD5base_*
rename TQ6_* TD7base_*
rename TQ7_* TD8base_*

rename TQ8_01 TDbase_teacher_motivation
rename TQ8_02 TDbase_teacher_enthusiasm
rename TQ8_03 TDbase_teacher_pride
rename TQ8_04 TDbase_teacher_studentresults
rename TQ8_05 TDbase_school_good_man
rename TQ8_06_01 TDbase_school_bad_man_reason1
rename TQ8_06_02 TDbase_school_bad_man_reason2
rename TQ8_07 TDbase_satis_salary
rename TQ8_08 TDbase_satis_career
rename TQ8_09 TDbase_school_good
rename TQ8_10_01 TDbase_school_bad_reason1
rename TQ8_10_02 TDbase_school_bad_reason2

rename TQ9_* TD10base_*
rename TQ10_* TD11base_*
rename TQ11_* TD12base_*
rename TQ12_* TD13base_*
rename TQ13_* TD14base_*

destring TDbase_04_12_02_money, replace
rename TDbase_04_12_02_gift TDbase_04_12_02_gift_specified
destring TD13base_04_num, replace

save "data_teachers_baseline2.dta", replace





// Director survey

use "data_director_baseline.dta", clear

rename D_resp_tel TD_resp_tel

merge m:1 TD_resp_tel using "data_teachers_endline2.dta"

drop if school_id==.

// corrections

replace teacher_id2 = 588 if school_id==5
replace teacher_id2 = 1288 if school_id==12
replace teacher_id2 = 1888 if school_id==18
replace teacher_id2 = 2188 if school_id==21
replace teacher_id2 = 2801 if school_id==28
replace teacher_id2 = 2988 if school_id==29
replace teacher_id2 = 3488 if school_id==34
replace teacher_id2 = 3588 if school_id==35
replace teacher_id2 = 4288 if school_id==42
replace teacher_id2 = 5488 if school_id==54
replace teacher_id2 = 5604 if school_id==56
replace teacher_id2 = 5788 if school_id==57
replace teacher_id2 = 6301 if school_id==63
replace teacher_id2 = 7488 if school_id==74
replace teacher_id2 = 7788 if school_id==77
replace teacher_id2 = 9688 if school_id==96
replace teacher_id2 = 10488 if school_id==104
replace teacher_id2 = 10616 if school_id==106
replace teacher_id2 = 10888 if school_id==108
replace teacher_id2 = 12188 if school_id==121
replace teacher_id2 = 12288 if school_id==122
replace teacher_id2 = 12488 if school_id==124
replace teacher_id2 = 12688 if school_id==126

gen changed = 0
replace changed = 1 if school_id!=TD_school_id

lab var changed "Changed school between baseline and endline"


drop _merge TD_ss_key TD_school_id TD_resp_id TD_resp_tel TD_resp_name

drop 	DP2_1_C12 DP2_38 DP2_3_C_8 DP2_6_C7 DP2_7_C_5 DP2_15_C_8 DP2_20_C_6 ///
		DP2_24_C_10 DP2_25_C_6 DP2_26_C_6 DP2_27_C_6 DP2_281 DP2_282 		///
		DP2_283 DP2_284 DP2_285 DP2_286 DP2_28_C_4 DP2_30_C_9 DP2_31_Codes 	///
		DP3_8_C6 DP3_10_C5 DP4_4_C5 DP4_5_C9 DP4_6_C9 DP4_7_C7 DP5_2_C11 	///
		DP5_41_C10 DP7_3_C6 DP7_4_C6 DP7_5_C5 DP8_1_C4 DP8_2_Other 			///
		DP8_3_C12 DP8_6_C6 DP9_1A_C80 DP9_1B_C81 DP9_1C_C82 DP9_30 			///
		DP9_30_Codes DP10_1A_C90 DP10_1B_C91 DP10_1C_C92 DP11_8_C9 			///
		DP12_12_C5 DP12_149 DP12_14_C10 DP14_4_1_C13 DP14_4_2_C13 			///
		DP14_4_3_C13 DP14_5_1_C DP14_5_2_C DP14_5_3_C DP14_7_2_C2 			///
		DP14_7_3_C2 DP14_7_2_C6 DP14_7_3_C6 DP14_9_1_C DP14_9_2_C 			///
		DP14_9_3_C DP14_10_1_C DP14_10_2_C DP14_10_3_C DP14_11_1_C7 		///
		DP14_11_2_C7 DP14_11_3_C7 DP15_8_C10 DP15_11_C13 					///
		DP16_1_C1_Q2_Codes DP16_1_C2_Q2_Codes DP16_1_C3_Q2_Codes 			///
		DP16_1_C4_Q2_Codes DP16_1_C5_Q2_Codes DP16_1_C6_Q2_Codes 			///
		DP16_1_C7_Q2_Codes DP16_1_C8_Q2_Codes DP16_1_C9_Q2_Codes 			///
		DP16_1_C10_Q2_Codes DP16_1_C11_Q2_Codes DP16_1_C12_Q2_Codes 		///
		DP16_1_C13_Q2_Codes DP16_1_C14_Q2_Codes DP16_1_C15_Q2_Codes 		///
		DP16_1_C16_Q2_Codes DP16_1_C17_Q2_Codes DP16_1_C18_Q2_Codes 		///
		DP1_20_C6 DP2_13 DP6_4_Other DP6_6_C10

gen survey_type = 3

order school_id teacher_id2 changed survey_type

lab var teacher_id2 "Identification for merging"


rename D_* *

drop resp_id school_name vil_id commune_name bairro_name

rename resp_position director_type

rename DQ1_01 TDbase_age
rename DQ1_02 TDbase_female
rename DQ1_03 TDbase_home_loc2
rename DQ1_03_01 TDbase_home_loc2_other1
rename DQ1_03_02 TDbase_home_loc2_other2
rename DQ1_03_03 TDbase_home_loc2_other3
rename DQ1_04 TDbase_origin_muni
rename DQ1_05 TDbase_origin2
rename DQ1_05_01 TDbase_origin2_other1
rename DQ1_05_02 TDbase_origin2_other2
rename DQ1_05_03 TDbase_origin2_other3
rename DQ1_06 TDbase_leaving_origin
rename DQ1_07 TDbase_arriving_home
rename DQ1_08 TDbase_marital
rename DQ1_09 TDbase_edu_partner
rename DQ1_10 TDbase_ocu_partner
rename DQ1_11 TDbase_income
rename DQ1_12 TDbase_children
rename DQ1_13 TDbase_children_others
rename DQ1_14 TDbase_children_girls
rename DQ1_15 TDbase_children_school
rename DQ1_16_01 TDbase_child1_grade
rename DQ1_16_02 TDbase_child2_grade
rename DQ1_16_03 TDbase_child3_grade
rename DQ1_16_04 TDbase_child4_grade
rename DQ1_16_05 TDbase_child5_grade
rename DQ1_16_06 TDbase_child6_grade
rename DQ1_16_07 TDbase_child7_grade
rename DQ1_16_08 TDbase_child8_grade
rename DQ1_17 TDbase_language
rename DQ1_18 TDbase_home_type
rename DQ1_19 TDbase_transport_distance
rename DQ1_20 TDbase_transport_type
rename DQ1_21 TDbase_transport_time
rename DQ2_01 TDbase_edu
rename DQ2_01_uni TDbase_edu_uni_years
rename DQ2_01_pos TDbase_edu_pos_years
rename DQ2_02 Dbase_schoolman_training
rename DQ2_03_01 TDbase_training_1
rename DQ2_03_02 TDbase_training_2
rename DQ2_03_03 TDbase_training_3
rename DQ2_03_04 TDbase_training_4
rename DQ2_03_05 TDbase_training_5
rename DQ2_03_06 TDbase_training_6
rename DQ2_03_07 TDbase_training_7
rename DQ2_04_month Dbase_dir_this_school_month
rename DQ2_04_year Dbase_dir_this_school_year
rename DQ2_05 Dbase_help_nomination
rename DQ2_06_01 Dbase_help_nomination_1
rename DQ2_06_02 Dbase_help_nomination_2
rename DQ2_06_03 Dbase_help_nomination_3
rename DQ2_06_04 Dbase_help_nomination_4
rename DQ2_06_05 Dbase_help_nomination_5
rename DQ2_06_06 Dbase_help_nomination_6
rename DQ2_06_07 Dbase_help_nomination_7
rename DQ2_06_08 Dbase_help_nomination_8
rename DQ2_07 Dbase_dir_nomination
rename DQ2_08 Dbase_deputy_this_school
rename DQ2_09 Dbase_dir_other_school
rename DQ2_10 Dbase_name_other_school
rename DQ2_11 Dbase_loc1_other_school
rename DQ2_12 Dbase_loc2_other_school
rename DQ2_13 Dbase_dir_other_school_year
rename DQ2_14 Dbase_dir_other_school_years
rename DQ2_15 Dbase_transfer_reason
rename DQ2_15_other Dbase_transfer_reason_other
rename DQ2_16 Dbase_teach
rename DQ2_17 Dbase_teach_this_school_years
rename DQ2_18 Dbase_teach_this_sch_yea_before
rename DQ2_19 Dbase_teach_other_sch_yea_before
rename DQ2_20 TDbase_stay
rename DQ2_21 TDbase_salary
rename DQ2_22 TDbase_bonus_possible
rename DQ2_23 TDbase_bonus_received
rename DQ2_24_01 TDbase_evaluation_how_1
rename DQ2_24_02 TDbase_evaluation_how_2
rename DQ2_24_03 TDbase_evaluation_how_3
rename DQ2_24_04 TDbase_evaluation_how_4
rename DQ2_24_05 TDbase_evaluation_how_5
rename DQ2_24_06 TDbase_evaluation_how_6
rename DQ2_24_07 TDbase_evaluation_how_7
rename DQ2_24_08 TDbase_evaluation_how_8
rename DQ2_24_09 TDbase_evaluation_how_9
rename DQ2_24_10 TDbase_evaluation_how_10
rename DQ2_24_11 TDbase_evaluation_how_11
rename DQ2_24_12 TDbase_evaluation_how_12
rename DQ2_25 TDbase_evaluation_who
rename DQ2_26 Dbase_consequence_good
rename DQ2_27 Dbase_consequence_bad
rename DQ2_28 TDbase_receive_help
rename DQ2_29 TDbase_other_income
rename DQ2_30 Dbase_other_income_type
rename DQ2_31 TDbase_other_income_value

rename DQ3_* TDbase_04_*
rename DQ4_* TD4base_*

rename	DQ5_01	TD5base_01
rename	DQ5_02_01	TD5base_02_01
rename	DQ5_02_02	TD5base_02_02
rename	DQ5_02_03	TD5base_02_03
rename	DQ5_02_04	TD5base_02_04
rename	DQ5_02_05	TD5base_02_05
rename	DQ5_02_06	TD5base_02_06
rename	DQ5_02_07	TD5base_02_07
rename	DQ5_02_08	TD5base_02_08
rename	DQ5_02_09	TD5base_02_09
rename	DQ5_02_10	TD5base_02_10
rename	DQ5_02_11	TD5base_02_11
rename	DQ5_03_01	TD5base_03_01
rename	DQ5_03_02	TD5base_03_02
rename	DQ5_03_03	TD5base_03_03
rename	DQ5_03_04	TD5base_03_04
rename	DQ5_03_05	TD5base_03_05
rename	DQ5_03_06	TD5base_03_06
rename	DQ5_03_07	TD5base_03_07
rename	DQ5_03_08	TD5base_03_08
rename	DQ5_03_09	TD5base_03_09
rename	DQ5_03_10	TD5base_03_10
rename	DQ5_03_11	TD5base_03_11
rename	DQ5_04	TD5base_07
rename	DQ5_04_01	TD5base_07_01
rename	DQ5_04_02	TD5base_07_02
rename	DQ5_04_03	TD5base_07_03
rename	DQ5_04_04	TD5base_07_04
rename	DQ5_04_05	TD5base_07_05
rename	DQ5_04_06	TD5base_07_06
rename	DQ5_04_07	TD5base_07_07
rename	DQ5_04_08	TD5base_07_08
rename	DQ5_04_09	TD5base_07_09
rename	DQ5_04_10	TD5base_07_10
rename	DQ5_04_11	TD5base_07_11
rename	DQ5_05_01	TD5base_08_01
rename	DQ5_05_02	TD5base_08_02
rename	DQ5_05_03	TD5base_08_03
rename	DQ5_05_04	TD5base_08_04
rename	DQ5_05_05	TD5base_08_05
rename	DQ5_05_06	TD5base_08_06
rename	DQ5_05_07	TD5base_08_07
rename	DQ5_05_08	TD5base_08_08
rename	DQ5_05_09	TD5base_08_09
rename	DQ5_05_10	TD5base_08_10
rename	DQ5_05_11	TD5base_08_11
rename	DQ5_06_01	TD5base_09_01
rename	DQ5_06_02	TD5base_09_02
rename	DQ5_06_03	TD5base_09_03
rename	DQ5_06_04	TD5base_09_04
rename	DQ5_06_05	TD5base_09_05
rename	DQ5_06_06	TD5base_09_06
rename	DQ5_06_07	TD5base_09_07
rename	DQ5_06_08	TD5base_09_08
rename	DQ5_06_09	TD5base_09_09
rename	DQ5_06_10	TD5base_09_10
rename	DQ5_06_11	TD5base_09_11


rename DQ6_* TD6abase_*
rename DQ7_* TD6bbase_*
rename DQ8_* TD6cbase_*

rename DQ9_* TD7base_*
rename DQ10_* TD8base_*

rename DQ11_01 TDbase_teacher_motivation
rename DQ11_02 TDbase_teacher_enthusiasm
rename DQ11_03 TDbase_teacher_pride
rename DQ11_04 TDbase_teacher_studentresults
rename DQ11_05 TDbase_satis_salary
rename DQ11_06 TDbase_satis_career
rename DQ11_07 TDbase_school_good
rename DQ11_08_01 TDbase_school_bad_reason1
rename DQ11_08_02 TDbase_school_bad_reason2

rename DQ12_* TD10base_*
rename DQ13_* TD11base_*
rename DQ14_* TD12base_*
rename DQ15_* TD13base_*
rename DQ16_* TD14base_*

save "data_director_baseline2.dta", replace


/// Append the two surveys


append using "data_teachers_baseline2.dta"

lab def survey_type 2 "Teacher" 3 "Director"
lab val survey_type survey_type

lab var survey_type "Survey type"

replace changed = . if teacher_id2==.

order preschool grade1 grade2 grade3 grade4 grade5 grade6, after(director_type)

order Tbase_school_ocu Tbase_qualification, after(TDbase_transport_time)

order Tbase_teach_other_school_years Tbase_name_other_school 				///
	Tbase_loc1_other_school Tbase_loc2_other_school Tbase_transfer_reason 	///
	Tbase_teach_this_school_years Tbase_help_nomination 					///
	Tbase_help_nomination_type , after(TDbase_training_7)

order TDbase_edu TDbase_edu_uni_years TDbase_edu_pos_years, 				///
	after(TDbase_arriving_home)

order Tbase_consequence_good_1 Tbase_consequence_good_2 					///
Tbase_consequence_good_3 Tbase_consequence_good_4 Tbase_consequence_good_5 	///
Tbase_consequence_good_6 , after(Dbase_consequence_good)

order Tbase_consequence_bad_1 Tbase_consequence_bad_2 						///
Tbase_consequence_bad_3 Tbase_consequence_bad_4 Tbase_consequence_bad_5 	///
Tbase_dir_can_dismiss , after(Dbase_consequence_bad)

order Tbase_other_income_type1 Tbase_other_income_type2 					///
	Tbase_other_income_type3 Tbase_other_income_type4 						///
	Tbase_other_income_type5 Tbase_other_income_type6 						///
	Tbase_other_income_type7 Tbase_other_income_type8, 						///
	after(Dbase_other_income_type)

order TD3base_01_01 TD3base_01_02 TD3base_02_00 TD3base_02_01 				///
	TD3base_02_02 TD3base_02_03 TD3base_02_04 TD3base_02_05 TD3base_02_06 	///
	TD3base_03_00 TD3base_03_01 TD3base_03_02 TD3base_03_03 TD3base_03_04 	///
	TD3base_03_05 TD3base_03_06 TD3base_04_00 TD3base_04_01 TD3base_04_02 	///
	TD3base_04_03 TD3base_04_04 TD3base_04_05 TD3base_04_06 TD3base_05_00 	///
	TD3base_05_01 TD3base_05_02 TD3base_05_03 TD3base_05_04 TD3base_05_05 	///
	TD3base_05_06 TD3base_06_01 TD3base_06_02 TD3base_06_03 TD3base_06_04  	///
	TD3base_06_05 TD3base_06_06 TD3base_06_07 TD3base_06_08  				///
	TD3base_06_08_other TD3base_07 TD3base_08 TD3base_09_01 TD3base_09_02  	///
	TD3base_10_00 TD3base_10_01 TD3base_10_02 TD3base_10_03 TD3base_10_04  	///
	TD3base_10_05 TD3base_10_06 TD3base_11 TD3base_12_00 TD3base_12_01  	///
	TD3base_12_02 TD3base_12_03 TD3base_12_04 TD3base_12_05 TD3base_12_06  	///
	TD3base_13_00_01 TD3base_13_01_01 TD3base_13_01_02 TD3base_13_02_01  	///
	TD3base_13_02_02 TD3base_13_03_01 TD3base_13_03_02 TD3base_13_04_01  	///
	TD3base_13_04_02 TD3base_13_05_01 TD3base_13_06_01 TD3base_14_00  		///
	TD3base_14_01 TD3base_14_02 TD3base_14_03 TD3base_14_04 TD3base_14_05  	///
	TD3base_14_06 TD3base_15 TD3base_15_00 TD3base_15_01 TD3base_15_02  	///
	TD3base_15_03 TD3base_15_04 TD3base_15_05 TD3base_15_06 TD3base_16_00  	///
	TD3base_16_01 TD3base_16_02 TD3base_16_03 TD3base_16_04 TD3base_16_05  	///
	TD3base_16_06 TD3base_17 TD3base_18_01 TD3base_18_02 TD3base_18_03  	///
	TD3base_19_00 TD3base_19_01 TD3base_19_02 TD3base_19_03 TD3base_19_04  	///
	TD3base_19_05 TD3base_19_06 TD3base_20 TD3base_21_00 TD3base_21_01  	///
	TD3base_21_02 TD3base_21_03 TD3base_21_04 TD3base_21_05 TD3base_21_06  	///
	TD3base_22 TD3base_23 TD3base_24 TD3base_25 TD3base_26 TD3base_27  		///
	TD3base_28 TD3base_29 TD3base_30 TD3base_31_01 TD3base_31_01_other  	///
	TD3base_31_02 TD3base_31_02_other TD3base_31_03 TD3base_31_03_other  	///
	TD3base_32 TD3base_33 TD3base_34 TD3base_35 TD3base_36 TD3base_37  		///
	TD3base_38 TD3base_39 TD3base_40 TD3base_41 TD3base_42 TD3base_43,  	///
	after(TDbase_other_income_value)

order TDbase_04_08_01 TDbase_04_08_02, after(TDbase_04_08)

order TDbase_04_12_02_gift_specified, after(TDbase_04_12_02_gift)

order TDbase_school_good_man TDbase_school_bad_man_reason1  				///
TDbase_school_bad_man_reason2, after(TDbase_teacher_studentresults)

order TD12base_07_02_comuna TD12base_07_02_other, after(TD12base_07_02)

order TD5base_04 TD5base_05_01 TD5base_05_02 TD5base_05_03 TD5base_05_04  	///
TD5base_05_04_other TD5base_06, after(TD5base_03_11)

order TD5base_10_a TD5base_10_b TD5base_10_01 TD5base_10_02 TD5base_10_03  	///
TD5base_10_04 TD5base_10_05 TD5base_10_06 TD5base_10_07 TD5base_10_08  		///
TD5base_10_09 TD5base_10_10 TD5base_10_11 TD5base_11_01 TD5base_11_02  		///
TD5base_11_03 TD5base_11_04 TD5base_11_05 TD5base_11_06 TD5base_11_07  		///
TD5base_11_08 TD5base_11_09 TD5base_11_10 TD5base_11_11 TD5base_12_01  		///
TD5base_12_02 TD5base_12_03 TD5base_12_04 TD5base_12_05 TD5base_12_06  		///
TD5base_12_07 TD5base_12_08 TD5base_12_09 TD5base_12_10 TD5base_12_11,  	///
after(TD5base_09_11)

replace resp_idgame = "P026_5" if resp_name=="agela cipriano manuel vieira"

replace resp_idgame = "P067_4" if resp_name=="domingos jose papagaio"
replace resp_idgame = "P067_2" if resp_name=="julia maria mendez cabriel"
replace resp_idgame = "P067_1" if resp_name=="quintino joaquim kitutu"
replace resp_idgame = "P067_5" if resp_name=="enis jose cafranca"
replace resp_idgame = "" if resp_name=="Domingos Prazeres Antonio"
replace resp_idgame = "P063_1" if resp_name=="DOMINGOS PRAZERIS ANTONIO"

merge m:1 resp_idgame using "data_games_teachers.dta"

drop _merge newid school_name resp_idprof resp_name_survey survey matched resp_id

sort school_id teacher_id2

foreach var in 	date A1 A2_received sent200 sent400 sent600 sent800 		///
				faces A3 expect_group true_group{
		rename `var' Gtdbase_`var'
}

gen dir_can_match = 0

replace dir_can_match = 1 if teacher_id2 == 11605 & survey_type==3
replace teacher_id2 = . if teacher_id2 == 11605 & survey_type==3

replace dir_can_match = 1 if teacher_id2 == 8505 & survey_type==3
replace teacher_id2 = . if teacher_id2 == 8505 & survey_type==3

replace dir_can_match = 1 if teacher_id2 == 6702 & survey_type==3
replace teacher_id2 = . if teacher_id2 == 6702 & survey_type==3

replace dir_can_match = 1 if teacher_id2 == 6301 & survey_type==3
replace teacher_id2 = . if teacher_id2 == 6301 & survey_type==3

order dir_can_match, after(survey_type)

lab var dir_can_match "Director survey matches also"


foreach var in 	changed survey_type dir_can_match resp_idgame time_start 	///
				time_finish resp_name director_type preschool grade1 grade2 ///
				grade3 grade4 grade5 grade6{
		rename `var' TDbase_`var'
}

save "data_TDG_baseline.dta", replace

drop if teacher_id2==.

save "data_TDG_baseline_matchesonly.dta", replace


sum TDbase_age TDbase_female TDbase_edu TDbase_income Tbase_teach_this_school_years Tbase_teach_other_school_years TDbase_salary if TDbase_survey_type==2 & TDbase_changed==.
sum TDbase_age TDbase_female TDbase_edu TDbase_income Tbase_teach_this_school_years Tbase_teach_other_school_years TDbase_salary if TDbase_survey_type==2 & TDbase_changed==0
sum TDbase_age TDbase_female TDbase_edu TDbase_income Tbase_teach_this_school_years Tbase_teach_other_school_years TDbase_salary if TDbase_survey_type==2 & TDbase_changed==1
